using System;
using System.Collections.Generic;

namespace YouVisio.Silverlight.TextDiff
{
    public class Int32Retriever : IPartsRetriever<int[], int>
    {
        private int[] _source;
        private HashSet<int> _hashSet;

        public int[] Source { set { this.Set(value); } }
        public void Set(int[] source, IEqualityComparer<int> comparer = null)
        {
            this._source = source;
            this._hashSet = new HashSet<int>(comparer ?? EqualityComparer<int>.Default);
            if (this._source != null)
                foreach (var ch in this._source)
                    this._hashSet.Add(ch);
        }
        public int GetByIndex(int index)
        {
            return this._source[index];
        }
        public int Length
        {
            get
            {
                return this._source.Length;
            }
        }
        public bool Contains(int part)
        {
            return this._hashSet.Contains(part);
        }
        public bool IndexIsWithin(int index)
        {
            return index >= 0 && index < this.Length;
        }
    }
}